package com.czmh.etc.onlinepubsys.controller;

import com.czmh.etc.common.core.annotation.ApiVersion;
import com.czmh.etc.onlinepubsys.constants.GlobalStatusCode;
import com.czmh.etc.onlinepubsys.json.Json;
import com.czmh.etc.onlinepubsys.utils.ResponseJsonUtil;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

/**
 * @描述：ExceptionController
 * @author： Seven.
 * @创建日期：Jun 12, 2019 1:19:51 AM.
 * @版本：1.0.0
 */
@RestController
@RequestMapping(value = "/error")
@EnableConfigurationProperties({ServerProperties.class})
public class BaseErrorController implements ErrorController {
    /**
     * 实现错误路径,暂时无用
     * @see ExceptionMvcAutoConfiguration#containerCustomizer()
     * @return
     */
    @Override
    public String getErrorPath() {
        return "";
    }

    @RequestMapping(value = "/404")
    @ResponseStatus(value = HttpStatus.NOT_FOUND)
    public Json hand404eError() {
        return ResponseJsonUtil.getJson(GlobalStatusCode._404, GlobalStatusCode._404_MSG);
    }

    @RequestMapping(value = "/401")
    @ResponseStatus(value = HttpStatus.UNAUTHORIZED)
    public Json handle401Error() {
        return ResponseJsonUtil.getJson(GlobalStatusCode._401, GlobalStatusCode._401_MSG);
    }

    @RequestMapping(value = "/400")
    @ResponseStatus(value = HttpStatus.BAD_REQUEST)
    public Json handle400Error() {
        return ResponseJsonUtil.getJson(GlobalStatusCode._400, GlobalStatusCode._400_MSG);
    }

    @RequestMapping(value = "/500")
    @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
    public Json handle500Error() {
        return ResponseJsonUtil.getJson(GlobalStatusCode._500, GlobalStatusCode._500_MSG);
    }
 
}